package com.pucheng.bracelet.ui.activity.message

import android.os.Bundle
import android.view.KeyEvent
import androidx.lifecycle.observe
import androidx.recyclerview.widget.LinearLayoutManager
import com.pucheng.bracelet.R
import com.pucheng.bracelet.databinding.ActivityMsgPushBinding
import com.pucheng.bracelet.ui.adapter.ClockData
import com.pucheng.bracelet.ui.adapter.PushAdapter
import com.pucheng.bracelet.ui.adapter.PushData
import com.pucheng.bracelet.viewmodel.meaasge.MsgPushViewModel
import kotlinx.android.synthetic.main.layout_title.*
import me.hgj.jetpackmvvm.base.activity.BaseVmDbActivity

class MsgPushActivity : BaseVmDbActivity<MsgPushViewModel, ActivityMsgPushBinding>() {

    override fun layoutId(): Int = R.layout.activity_msg_push

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.apply {
            viewModel = mViewModel
            lifecycleOwner = this@MsgPushActivity
            rvPush.apply {
                layoutManager = LinearLayoutManager(this@MsgPushActivity)
            }
            ibtn_back.apply {
                setOnClickListener {
                    mViewModel.setPushDataToBle()
                    finish()
                }
            }
            tv_title.apply {
                text = "消息推送"
            }
        }
        mViewModel.apply {
            pushData.observe(this@MsgPushActivity){
               val mAdapter = PushAdapter({ index: Int, pushData: PushData ->
                   mViewModel.selectData(index, pushData)
               },it)
                mDatabind.rvPush.adapter = mAdapter
            }
        }
//        mAdapter.setOnItemClickListener { adapter, view, position -> mViewModel.selectData(position,mAdapter.) }
    }

    override fun createObserver() {
    }

    override fun dismissLoading() {
    }

    override fun showLoading(message: String) {

    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK){
            mViewModel.setPushDataToBle()
        }
        return super.onKeyDown(keyCode, event)
    }

}